package com.atguigu.java.ai.langchain4j.config;

import dev.langchain4j.memory.ChatMemory;
import dev.langchain4j.memory.chat.ChatMemoryProvider;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.service.MemoryId;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: Mikey
 * @Date: 2025/8/29 10:08
 * @Description:
 **/
//@Configuration
public class MemoryConfig {
    @Bean
    public ChatMemory chatMemory(){
        MessageWindowChatMemory messageWindowChatMemory = MessageWindowChatMemory.withMaxMessages(10);
//        MessageWindowChatMemory messageWindowChatMemory1 = MessageWindowChatMemory.withMaxMessages(10);
        return messageWindowChatMemory;
    }


    @Bean
    public ChatMemoryProvider chatMemoryProviders(){
//        return new ChatMemoryProvider() {
//            @Override
//            public ChatMemory get(Object memoryId) {
//                return MessageWindowChatMemory.builder()
//                        .id(memoryId)
//                        .maxMessages(10)
//                        .build();
//            }
//        }
        //使用lambda表达式简化匿名内部类
//        return memoryId ->
//            MessageWindowChatMemory.builder()
//                    .id(memoryId)
//                    .maxMessages(10)
//                    .build();


        return memoryId->MessageWindowChatMemory.builder()
                .id(memoryId)
                .maxMessages(10)
                .build();
    }
}


